package com.zac.junit;

import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;

/**
 * 
 * A set of methods useful for stating assumptions about the conditions in which 
 * a test is meaningful. A failed assumption does not mean the code is broken, 
 * but that the test provides no useful information. The default JUnit runner 
 * treats tests with failing assumptions as ignored. 
 * Custom runners may behave differently.
 * 
 */
import static org.junit.Assume.assumeTrue;

@RunWith(Theories.class)
public class CounterTheories {
 
    @DataPoints 
    public static Counter[] data() {
        return new Counter[] {
            new Counter(0),
            new Counter(1),
            new Counter(-1),
            new Counter(Integer.MIN_VALUE),
            new Counter(Integer.MAX_VALUE), // overflows when incremented
        };
    }
 
    @Theory
    public void incrementTheory(Counter toIncrement) {
        int oldValue = toIncrement.getValue();
        assumeTrue(Integer.MAX_VALUE != oldValue);
        toIncrement.increment();
        int newValue = toIncrement.getValue();
        assertEquals(oldValue + 1, newValue);
    }
 
    //... more theories 
}
